import { userAppStore } from "@/stores/user";
import { useRoute } from "vue-router";
import { invokeAPi } from "@/xz-fn";
export default function () {
  const route = useRoute();
  const _userAppStore_ = userAppStore();
  async function onLoginFinish(ops: any, callback?: any) {
    localStorage.setItem("loginType", ops.loginType)
    _userAppStore_.setToken(ops.code);
    _userAppStore_.setLoginState(true);

    const userInfo = {
      status: 1,
      info: {
        isAutoLogin: ops.isAutoLogin,
        code: ops.code,
        uid: ops.uid + "",
        username: ops.user_name,
        headimgurl: ops.head_image,
        expire: ops.expire,
        svr_time: ops.svr_time
      }
    };
    invokeAPi("xz_set_userInfo", JSON.stringify(userInfo));
    if (route.name === "Login") {
      invokeAPi("jsMsg_SetWndStatus", 0);
    } else {
      _userAppStore_.getUserInfo();
    }
    _userAppStore_.setACDialogType("");
    typeof callback === "function" && callback();
  }

  return { onLoginFinish };
}
